package com.bwie.product.controller;

import com.bwie.common.doamin.dto.BoughtProductDTO;
import com.bwie.common.doamin.dto.ProductDTO;
import com.bwie.common.doamin.vo.ProductVO;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 产品控制层
 *
 * @author <a href="mailto:2943147140@qq.com">刘洋朔</a>
 * @version 1.0
 * @description: 产品控制层
 * @date 2025/9/9 14:22
 */
@RestController
@CrossOrigin
public class ProductController {
    /**
     * 产品控制层
     */
    @Autowired
    private ProductService productService;

    /**
     * 获取所有产品列表
     * @return
     */
    @PostMapping("selAllProductList")
    public Result<PageResult<ProductVO>> selAllProductList(@RequestBody ProductDTO productDTO){
        PageResult<ProductVO> pageResult = productService.selAllProductList(productDTO);
        return Result.success(pageResult);
    }


    /**
     * 回显商品
     * @return
     */
    @GetMapping("echoProduct/{productId}")
    public Result<Void> echoProduct(@PathVariable("productId") Long productId){
        productService.echoProduct(productId);
        return Result.success();
    }


    /**
     * 购买产品
     * @return
     */
    @PostMapping("boughtProducts")
    public Result<Void> boughtProducts(@Valid @RequestBody BoughtProductDTO boughtProductDTO){
        productService.boughtProducts(boughtProductDTO);
        return Result.success();
    }


    /**
     * 防抖
     * @return
     */
    @PostMapping("boughtToken")
    public Result<String> boughtToken(){
        String token = productService.boughtToken();
        return Result.success(token);
    }

}
